//
// CIndexBuffer.java
// Copyright (C) 2010  "Naush" <naush _ hotmail _ fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>./* ----------------------------------------------------------------------------







package org.ryzom.nel.threed;

import org.ryzom.nel.misc.CRefCount;
import org.ryzom.nel.misc.IStream;

public class CIndexBuffer extends CRefCount {
  private long swigCPtr;

  public CIndexBuffer(long cPtr, boolean cMemoryOwn) {
    super(nel3dJNI.CIndexBuffer_SWIGUpcast(cPtr), cMemoryOwn);
    swigCPtr = cPtr;
  }

  public static long getCPtr(CIndexBuffer obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        nel3dJNI.delete_CIndexBuffer(swigCPtr);
      }
      swigCPtr = 0;
    }
    super.delete();
  }

  public void setDrvInfos(SWIGTYPE_p_CRefPtrT_NL3D__IIBDrvInfos_t value) {
    nel3dJNI.CIndexBuffer_DrvInfos_set(swigCPtr, this, SWIGTYPE_p_CRefPtrT_NL3D__IIBDrvInfos_t.getCPtr(value));
  }

  public SWIGTYPE_p_CRefPtrT_NL3D__IIBDrvInfos_t getDrvInfos() {
    long cPtr = nel3dJNI.CIndexBuffer_DrvInfos_get(swigCPtr, this);
    return (cPtr == 0) ? null : new SWIGTYPE_p_CRefPtrT_NL3D__IIBDrvInfos_t(cPtr, false);
  }

  public long getTouchFlags() {
    return nel3dJNI.CIndexBuffer_getTouchFlags(swigCPtr, this);
  }

  public void setLocation(CIndexBuffer.TLocation newLocation) {
    nel3dJNI.CIndexBuffer_setLocation(swigCPtr, this, newLocation.swigValue());
  }

  public void fillBuffer() {
    nel3dJNI.CIndexBuffer_fillBuffer(swigCPtr, this);
  }

  public CIndexBuffer() {
    this(nel3dJNI.new_CIndexBuffer__SWIG_0(), true);
  }

  public CIndexBuffer(String name) {
    this(nel3dJNI.new_CIndexBuffer__SWIG_1(name), true);
  }

  public CIndexBuffer(CIndexBuffer vb) {
    this(nel3dJNI.new_CIndexBuffer__SWIG_2(CIndexBuffer.getCPtr(vb), vb), true);
  }

  public CIndexBuffer assign(CIndexBuffer vb) {
    return new CIndexBuffer(nel3dJNI.CIndexBuffer_assign(swigCPtr, this, CIndexBuffer.getCPtr(vb), vb), false);
  }

  public void setPreferredMemory(CIndexBuffer.TPreferredMemory preferredMemory, boolean keepLocalMemory) {
    nel3dJNI.CIndexBuffer_setPreferredMemory(swigCPtr, this, preferredMemory.swigValue(), keepLocalMemory);
  }

  public CIndexBuffer.TPreferredMemory getPreferredMemory() {
    return CIndexBuffer.TPreferredMemory.swigToEnum(nel3dJNI.CIndexBuffer_getPreferredMemory(swigCPtr, this));
  }

  public boolean getKeepLocalMemory() {
    return nel3dJNI.CIndexBuffer_getKeepLocalMemory(swigCPtr, this);
  }

  public CIndexBuffer.TLocation getLocation() {
    return CIndexBuffer.TLocation.swigToEnum(nel3dJNI.CIndexBuffer_getLocation(swigCPtr, this));
  }

  public boolean isResident() {
    return nel3dJNI.CIndexBuffer_isResident(swigCPtr, this);
  }

  public void setNumIndexes(long n) {
    nel3dJNI.CIndexBuffer_setNumIndexes(swigCPtr, this, n);
  }

  public void setFormat(CIndexBuffer.TFormat format) {
    nel3dJNI.CIndexBuffer_setFormat(swigCPtr, this, format.swigValue());
  }

  public CIndexBuffer.TFormat getFormat() {
    return CIndexBuffer.TFormat.swigToEnum(nel3dJNI.CIndexBuffer_getFormat(swigCPtr, this));
  }

  public long getIndexNumBytes() {
    return nel3dJNI.CIndexBuffer_getIndexNumBytes(swigCPtr, this);
  }

  public long getNumIndexes() {
    return nel3dJNI.CIndexBuffer_getNumIndexes(swigCPtr, this);
  }

  public void deleteAllIndexes() {
    nel3dJNI.CIndexBuffer_deleteAllIndexes(swigCPtr, this);
  }

  public void reserve(long nIndexes) {
    nel3dJNI.CIndexBuffer_reserve(swigCPtr, this, nIndexes);
  }

  public long capacity() {
    return nel3dJNI.CIndexBuffer_capacity(swigCPtr, this);
  }

  public void serial(IStream f) {
    nel3dJNI.CIndexBuffer_serial(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public void lock(CIndexBufferReadWrite accessor, long first, long last) {
    nel3dJNI.CIndexBuffer_lock__SWIG_0(swigCPtr, this, CIndexBufferReadWrite.getCPtr(accessor), accessor, first, last);
  }

  public void lock(CIndexBufferReadWrite accessor, long first) {
    nel3dJNI.CIndexBuffer_lock__SWIG_1(swigCPtr, this, CIndexBufferReadWrite.getCPtr(accessor), accessor, first);
  }

  public void lock(CIndexBufferReadWrite accessor) {
    nel3dJNI.CIndexBuffer_lock__SWIG_2(swigCPtr, this, CIndexBufferReadWrite.getCPtr(accessor), accessor);
  }

  public void lock(CIndexBufferRead accessor, long first, long last) {
    nel3dJNI.CIndexBuffer_lock__SWIG_3(swigCPtr, this, CIndexBufferRead.getCPtr(accessor), accessor, first, last);
  }

  public void lock(CIndexBufferRead accessor, long first) {
    nel3dJNI.CIndexBuffer_lock__SWIG_4(swigCPtr, this, CIndexBufferRead.getCPtr(accessor), accessor, first);
  }

  public void lock(CIndexBufferRead accessor) {
    nel3dJNI.CIndexBuffer_lock__SWIG_5(swigCPtr, this, CIndexBufferRead.getCPtr(accessor), accessor);
  }

  public boolean isLocked() {
    return nel3dJNI.CIndexBuffer_isLocked(swigCPtr, this);
  }

  public void setName(String name) {
    nel3dJNI.CIndexBuffer_setName(swigCPtr, this, name);
  }

  public String getName() {
    return nel3dJNI.CIndexBuffer_getName(swigCPtr, this);
  }

  public final static class TPreferredMemory {
    public final static TPreferredMemory RAMPreferred = new TPreferredMemory("RAMPreferred", nel3dJNI.CIndexBuffer_RAMPreferred_get());
    public final static TPreferredMemory AGPPreferred = new TPreferredMemory("AGPPreferred");
    public final static TPreferredMemory StaticPreferred = new TPreferredMemory("StaticPreferred");
    public final static TPreferredMemory RAMVolatile = new TPreferredMemory("RAMVolatile");
    public final static TPreferredMemory AGPVolatile = new TPreferredMemory("AGPVolatile");
    public final static TPreferredMemory PreferredCount = new TPreferredMemory("PreferredCount");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static TPreferredMemory swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + TPreferredMemory.class + " with value " + swigValue);
    }

    private TPreferredMemory(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private TPreferredMemory(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private TPreferredMemory(String swigName, TPreferredMemory swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static TPreferredMemory[] swigValues = { RAMPreferred, AGPPreferred, StaticPreferred, RAMVolatile, AGPVolatile, PreferredCount };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

  public final static class TLocation {
    public final static TLocation RAMResident = new TLocation("RAMResident", nel3dJNI.CIndexBuffer_RAMResident_get());
    public final static TLocation AGPResident = new TLocation("AGPResident");
    public final static TLocation VRAMResident = new TLocation("VRAMResident");
    public final static TLocation NotResident = new TLocation("NotResident");
    public final static TLocation LocationCount = new TLocation("LocationCount");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static TLocation swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + TLocation.class + " with value " + swigValue);
    }

    private TLocation(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private TLocation(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private TLocation(String swigName, TLocation swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static TLocation[] swigValues = { RAMResident, AGPResident, VRAMResident, NotResident, LocationCount };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

  public final static class TFormat {
    public final static TFormat Indices16 = new TFormat("Indices16", nel3dJNI.CIndexBuffer_Indices16_get());
    public final static TFormat Indices32 = new TFormat("Indices32");
    public final static TFormat IndicesUnknownFormat = new TFormat("IndicesUnknownFormat");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static TFormat swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + TFormat.class + " with value " + swigValue);
    }

    private TFormat(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private TFormat(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private TFormat(String swigName, TFormat swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static TFormat[] swigValues = { Indices16, Indices32, IndicesUnknownFormat };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

  public final static int TouchedIndexFormat = nel3dJNI.CIndexBuffer_TouchedIndexFormat_get();
  public final static int TouchedNumIndexes = nel3dJNI.CIndexBuffer_TouchedNumIndexes_get();
  public final static int TouchedReserve = nel3dJNI.CIndexBuffer_TouchedReserve_get();
  public final static int TouchedAll = nel3dJNI.CIndexBuffer_TouchedAll_get();

}
